new Vue({
  el: '#app',
  data: {
    id: '',
    loading: true,
    fileList: [],
    file: ''
  },
  mounted () {
    this.loading = false
    this.main()
  },
  methods: {
    onClickLeft: function () {
      history.go(-1)
    },
    async main() {
    },
    async afterRead(files) {
    },
    async onSubmit() {
      if(!this.fileList[0]) {
        this.$toast.fail('请上传图片')
        return;
      }

      let formData = new FormData()
      formData.append('image', this.fileList[0].content)
      $http.upload('/api/user/upload', formData).then(res => {
        let avatar = res.data.data
        return $http.post('/api/user/profile', { avatar: avatar })
      }).then(res => {
        if (res.data.code != 1) { return this.$toast(res.data.msg) }
  
        this.$toast.success({
          message: '修改成功',
          onClose: function () { history.go(-1) }
        })
      })
      
      
    }
  }
})